package edu.jd.movieplatform.user.ticket.impl;

import edu.jd.movieplatform.user.order.OrderDto;
import edu.jd.movieplatform.user.ticket.*;
import edu.jd.movieplatform.user.ticket.dao.TicketDao;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service
@Transactional
public class TicketServiceImpl implements TicketService {
    @Resource
    private TicketDao ticketDao;

    @Override
    public List<TicketDto> generateTicket(OrderDto[] orderDtoList, int order_num) {
        for(OrderDto dto:orderDtoList){
            Ticket ticket = new Ticket(dto);
            ticketDao.insertTicket(ticket);
        }

        List<TicketDto> tick_num_List = ticketDao.getTicket_num(order_num);
        /*List<TicketDto> tickList = new ArrayList<>();
        for(Integer tick_num : tick_num_List){
            TicketDto temp = new TicketDto((int)tick_num);
            tickList.add(temp);
        }*/
        return tick_num_List;
    }

    @Override
    public void addTemp(Ticket_temp temp){
        ticketDao.insertTemp(temp);
    }

    @Override
    public List<Ticket_temp> getTemp(String username){
        return ticketDao.findTemp(username);
    }

    @Override
    public void deleteTemp(Ticket_temp temp){
        ticketDao.deleteTemp(temp);
    }

    @Override
    public void deleteAllTemp(String username){
        ticketDao.deleteAllTempByUsername(username);
    }

    @Override
    public List<SeatDto> getSelectedSeats(SeatQueryDto dto){
        return ticketDao.findSelectedSeat(dto);
    }

    @Override
    public List<Ticket> getTickets(String username){
        return ticketDao.getTicketsByUsername(username);
    }
}
